/*
 * @lc app=leetcode.cn id=14 lang=javascript
 *
 * [14] 最长公共前缀
 */

// @lc code=start
/**
 * @param {string[]} strs
 * @return {string}
 */
var longestCommonPrefix = function (strs) {
  strs.sort();
  const n = strs.length;
  let cnt = 0;
  for (let i = 0; i < strs[0].length; i++) {
    if (strs[0][i] !== strs[n - 1][i]) break;
    cnt++;
  }

  return strs[0].slice(0, cnt);
};
// @lc code=end
